package com.yunxiang.controller;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.yunxiang.plugin.SqlManager;
import com.yunxiang.service.DriverService;

public class DriverController extends Controller{

	private DriverService driverService = new DriverService();
	/**
	 * 绑定车牌号与司机
	 */
	public void bind(){
		//获取参数
		String mobile = getPara("mobile");
		String car_num = getPara("car_num");
		String openId = (String)getSessionAttr("openId");
		JSONObject result = new JSONObject();
		
		Integer bindResult = driverService.bind(mobile, car_num, openId);
		
		if(0 == bindResult){
			result.put("code", 0);
			result.put("message", "绑定成功");
		}
		if(-1 == bindResult){
			result.put("code", -1);
			result.put("message", "车牌号或电话号码不正确");
		}
		if(-2 == bindResult){
			result.put("code", -2);
			result.put("message", "超过允许绑定的司机人数");
		}
		
		renderJson(result.toString());
	}
	
}
